<!-- 简历查询详情 -->

<template>
  <ul class="interview-common-detail resume-select-detail-container">
    <li class="resume-detail-left">
      <InterviewDetailLeftNav
        :userInfo="userInfo"
        :navs="navs"
        :nominateInfo="nominateInfo"
      ></InterviewDetailLeftNav>
    </li>
    <li class="resume-detail-right">
      <div>
        <InterviewDetailNotGo
          :notGoData="notGoData"
          :tipText="'简历反馈'"
        ></InterviewDetailNotGo>
      </div>
      <div class="module-box is-active-tab" v-bind:mode-type="'candidate'">
        <interview-detail-candidate
          :candidateInfo="candidateData"
        ></interview-detail-candidate>
      </div>
      <div class="module-box" v-bind:mode-type="'demand'">
        <interview-detail-demand
          :textDatas="demandData"
          :isShowInterviewBox="false"
        ></interview-detail-demand>
      </div>
    </li>
  </ul>
</template>
<script>
import bus from "@/eventBus";
import { dec_demandDetail } from "@/decs/dec_interviewDemandDetail";
import InterviewDetailLeftNav from "@/components/detailCommons/interviewDetailLeftNav";
import InterviewDetailCandidate from "@/components/detailCommons/interviewDetailCandidate";
import InterviewDetailDemand from "@/components/DemandDetail";
import InterviewDetailNotGo from "@/components/detailCommons/interviewDetailNotGo";

function fetchResumeDetailInfo(store, opts) {
  return store.dispatch("FETCH_RESUME_BYID", opts);
}
export default {
  created() {
    const { id } = this.$route.params;
    if (id) {
      this.fetchDetailData(id);
    }
  },
  mounted() {
    bus.$on("select-tab", this.selectTabItem);
  },
  beforeDestroy() {
    bus.$off("select-tab", this.selectTabItem);
  },
  beforeRouteEnter(to, from, next) {
    console.log(to, from)
    next();
  },
  beforeRouteLeave(to, from, next) {
    console.log(to.fullPath, from.fullPath)
    next();
  },
  methods: {
    // * 获取详情数据
    async fetchDetailData(needsCvId) {
      await fetchResumeDetailInfo(this.$store, { needsCvId });
      let { state, data } = this.$store.getters.getSelectResumeLDetail;
      if (state === "0000") {
        const { referrerInfo, cvdbInfo, cvdbState, needsDetails, depts } =
          data || {};
        if (referrerInfo) {
          this.nominateInfo = {
            name: referrerInfo.uploader_name,
            phone: referrerInfo.uploader_mobile,
            email: referrerInfo.uploader_email,
            companyName: referrerInfo.supplierName,
          };
        }
        if (cvdbInfo) {
          const { is_selected, selected_remark } = cvdbState;
          // * is_selected: 简历状态 0-未通过  1-已通过  2-已入场  5-已离场
          const resultText = [
            "简历不通过",
            "简历通过",
            "已入场",
            "",
            "",
            "已离场",
          ];
          if (is_selected == 0) {
            this.notGoData = {
              feed_back: selected_remark,
              text: "简历不通过",
              iconTxt: "icon-ku-mian",
              iconColor: "#cccccd",
            };
          } else {
            this.notGoData = {
              feed_back: selected_remark,
              text: resultText[is_selected],
              iconTxt: "icon-xiaolian-mian",
              iconColor: "#2bc27f",
            };
          }
          this.candidateData = {
            name: cvdbInfo.surname,
            record: cvdbInfo.education_code,
            handsOn: cvdbInfo.work_experience,
            isInJob: cvdbInfo.current_status_code,
            comeTime: cvdbInfo.post_time,
            phone: cvdbInfo.telephone,
            desc: cvdbInfo.reason,
          };
          this.userInfo.name = this.candidateData.name; // 候选人信息
          this.userInfo.zz = cvdbInfo.file_url; // 文件路径
          this.userInfo.fileName = cvdbInfo.fileName; // 文件路径
          this.userInfo.cvdbId = cvdbInfo.id; // 文件预览
        }
        if (needsDetails) {
          this.demandData = dec_demandDetail(needsDetails, "", "", "", depts);
          this.userInfo.ex = this.demandData.postCode; // 候选人信息
        }
      }
    },
    // * 切换tab
    selectTabItem(type) {
      _j("[mode-type=" + type + "]")
        .siblings(".module-box")
        .removeClass("is-active-tab");
      _j("[mode-type=" + type + "]").addClass("is-active-tab");
    },
  },
  data() {
    return {
      userInfo: {
        name: "",
        ex: "",
        zz: "",
      },
      navs: [
        {
          lable: "候选人信息",
          id: "2",
          val: "candidate",
          isActive: true,
        },
        {
          lable: "需求详情",
          id: "3",
          val: "demand",
          isActive: false,
        },
      ],
      nominateInfo: {
        name: "",
        phone: "",
        email: "",
        companyName: "",
      },
      notGoData: {
        feed_back: "",
        text: "",
        iconTxt: "",
        iconColor: "",
      },
      candidateData: {
        name: "",
        record: "",
        handsOn: "",
        isInJob: "",
        comeTime: "",
        phone: "",
        desc: "",
      },
      demandData: {
        jobName: "",
        jobType: "",
        moenyType: "",
        reportsTo: "",
        quantity: "",
        workingDeadline: "",
        workYears: "",
        jobAddress: "",
        budget: "",
        supplier: "",
        inJobTime: "",
        publishTime: "",
        jobDesc: "",
        jobAsk: "",
        needsCode: "",
        pathO: "",
        pathT: "",
        pathS: "",
        needsNumber: "",
      },
    };
  },
  components: {
    InterviewDetailCandidate,
    InterviewDetailDemand,
    InterviewDetailLeftNav,
    InterviewDetailNotGo,
  },
};
</script>
<style lang="scss">
@import "~@/assets/scss/mixins.scss";
@include Interview-detail;
</style>
